<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
  <th:block th:include="include :: header('修改整改任务')" />
  <th:block th:include="include :: bootstrap-fileinput-css"/>
  <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
  <form class="form-horizontal m" id="form-reform-edit" th:object="${inspectionReform}">
    <input name="reformId" th:field="*{reformId}" type="hidden">
    <input name="reformCheckid" th:field="*{reformCheckid}" type="hidden">
    <div class="form-group">
      <label class="col-sm-3 control-label">整改照片路径：</label>
      <div class="col-sm-8 fileinput fileinput-new" data-provides="fileinput">
        <div class="fileinput-preview thumbnail" data-trigger="fileinput" style="width: 200px; height: 150px;"></div>
        <div class="">
          <span class="btn btn-white btn-file"><span class="fileinput-new">选择图片</span><span class="fileinput-exists">更改</span> <input type="hidden" name="reformImgpath" th:field="*{reformImgpath}"><input id="filePath" type="file" th:field="*{reformImgpath}"></span>
          <a href="#" class="btn btn-white fileinput-exists" data-dismiss="fileinput">清除</a>
        </div>
      </div>
    </div>

  </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: bootstrap-fileinput-js"/>
<th:block th:include="include :: jasny-bootstrap-js" />
<th:block th:include="include :: select2-js" />
<script th:inline="javascript">
  var prefix = ctx + "model/reform";
  $("#form-reform-edit").validate({
    focusCleanup: true
  });

  function uploadFile(url) {
    var formData = new FormData();
    if ($('#filePath')[0].files[0] == null) {
      $.modal.alertWarning("请先选择文件路径");
      return false;
    }
    formData.append('reformId',$('#reformId').val());
    formData.append('file', $('#filePath')[0].files[0]);

    $.ajax({
      url: url,
      type: 'post',
      cache: false,
      data: formData,
      processData: false,
      contentType: false,
      dataType: "json",
      success: function(result) {
        $.operate.successCallback(result);
      }
    });
  }

  function submitHandler() {
    if ($.validate.form()) {
      /*$.operate.save(prefix + "/edit", $('#form-check-edit').serialize());*/
      uploadFile(prefix+"/edit");
    }
  }
</script>
</body>
</html>
